// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import axios from 'axios';
import 'element-ui/lib/theme-chalk/index.css'
import echarts from 'echarts'
import { setCookie,getCookie } from './assets/js/cookie'

Vue.prototype.$echarts = echarts;
Vue.config.productionTip = false;
Vue.prototype.$axios = axios;
Vue.use(ElementUI);

router.push("/")

router.beforeEach((to, from, next) => {
  if (getCookie('token')) {
    next()
  }
  else {
    next('/login')
  }
})


axios.interceptors.request.use(
  config => {
    // 这里写死一个token，你需要在这里取到你设置好的token的值
    const token = getCookie('token');
    if (token) {
      // 这里将token设置到headers中，header的key是Authorization，这个key值根据你的需要进行修改即可
      config.headers.Authorization = token;
    }
    return config
  },
  error => {
    return Promise.reject(error)
  });

new Vue({
  el: '#app',
  router,
  components: {App},
  template: '<App/>'
})
